//
//  PhotosTableViewCell.m
//  
//
//  Created by lanou on 15/12/18.
//
//

#import "PhotosTableViewCell.h"
#import "UIImageView+AFNetworking.h"


#define kPictureHeight 5

@implementation PhotosTableViewCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self= [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
         self.backgroundColor = [UIColor cyanColor];
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(kPictureHeight, kPictureHeight, kWidth - 10, 130)];
        view.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:view];
        
        _BigPictureView = [[UIImageView alloc]initWithFrame:(CGRectMake(kPictureHeight, kPictureHeight, kWidth / 3 - 5, kWidth / 3 - 5))];
        _BigPictureView.backgroundColor =[UIColor yellowColor];
        [view addSubview:_BigPictureView];
       
        _SmallPictureView1 = [[UIImageView alloc]initWithFrame:(CGRectMake(kWidth / 3 +2, kPictureHeight, kWidth / 3 - 66, kWidth / 3 - 66))];
        _SmallPictureView1.backgroundColor = [UIColor greenColor];
        [view addSubview:_SmallPictureView1];
       
        _SmallPictureView2 = [[UIImageView alloc]initWithFrame:(CGRectMake(kWidth / 3 + 2, kWidth / 3 - 59, kWidth / 3 - 66, kWidth / 3 - 66))];
        _SmallPictureView2.backgroundColor = [UIColor redColor];
        [view addSubview:_SmallPictureView2];
       
        _titleLabel = [[UILabel alloc]initWithFrame:(CGRectMake(kWidth / 2 + 2, 0,kWidth / 2 - 13, 50))];
        _titleLabel.numberOfLines = 0;
        _titleLabel.font = [UIFont boldSystemFontOfSize:16];
        [view addSubview:_titleLabel];
       
        _likeNumberLabel = [[UILabel alloc]initWithFrame:(CGRectMake(kWidth / 2 + 12, 40, 40, 40))];
        _likeNumberLabel.textColor = [UIColor orangeColor];
        [view addSubview:_likeNumberLabel];
        
        UIView *grayView = [[UIView alloc]initWithFrame:(CGRectMake(kWidth / 2 + 4, 80, 182, 1))];
        grayView.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:grayView];
        
        _AuthorFaceView = [[UIImageView alloc]initWithFrame:(CGRectMake(kWidth / 2 + 2, 82, 30, 30))];
        _AuthorFaceView.layer.masksToBounds = YES;
        _AuthorFaceView.layer.borderWidth = 2;
        _AuthorFaceView.layer.cornerRadius = _AuthorFaceView.bounds.size.width / 2;
        _AuthorFaceView.layer.borderColor = [UIColor clearColor].CGColor;
        [view addSubview:_AuthorFaceView];
       
        _AuthorNickLabel = [[UILabel alloc]initWithFrame:(CGRectMake(kWidth / 2 + 42, 82, 160, 25))];
        _AuthorNickLabel.textColor = [UIColor grayColor];
        [view addSubview:_AuthorNickLabel];
        
        
    }
    return self;
}



- (void)setPhotos:(Photos *)photos{
    self.smallArray = [[NSMutableArray alloc]init];
    if (_photos != photos) {
        _photos = photos;
        
        [_BigPictureView setImageWithURL:[NSURL URLWithString:photos.cover_pic]];
        _titleLabel.text = photos.title;
        _AuthorNickLabel.text = photos.author_nick;
        _likeNumberLabel.text = photos.liked_count;
        [_AuthorFaceView setImageWithURL:[NSURL URLWithString:photos.author_face]];
        
        for (NSDictionary *dic in photos.items) {
            
               Photos *photos =[Photos shareWithDictionary:dic];
            [self.smallArray addObject:photos];
            
        }
       
        Photos *photos1 = self.smallArray[0];
        
        [_SmallPictureView1 setImageWithURL:[NSURL URLWithString:photos1.pic]];
        Photos *photos2 = self.smallArray[1];
        
        [_SmallPictureView2 setImageWithURL:[NSURL URLWithString:photos2.pic]];
        
        
        
   
        
    }
    
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
